﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FacebookAcessLibrary.Data;
using FacebookAcessLibrary.FacebookClass;
using GiveGraphMappers;
using Microsoft.IdentityModel.Claims;
using WebApp.Util;

namespace WebApp.Controllers
{
    public class FacebookController : Controller
    {
        //
        // GET: /Facebook/

        public ActionResult Index()
        {
            return View("Canvas");
        }

        public ActionResult Canvas()
        {
            return RedirectToAction("ShowNotification",new{idUser=new UserMapper().Get(((IClaimsIdentity)User.Identity).GetUserId()).FacebookToken });
        }




        public ViewResult ShowNotification(long idUser)
        {
            var _facebook = new Notification();
            dynamic notification = _facebook.GetNotificationUser(idUser);

            return View("NotificationView",notification);
        }

        public ActionResult ClearNotification(long idUser, string url)
        {
            var _facebook = new Notification();
            _facebook.ClearNotificationUser(new List<long>() { idUser }, long.Parse(new UserMapper().Get(((IClaimsIdentity)User.Identity).GetUserId()).FacebookToken));

            return Redirect(url);
        }


        public ViewResult NotificationTest()
        {
            var data = new[]
                           {
                               new NotificationData
                                   {
                                       Key = 1,
                                       News = new News
                                                  {
                                                      Message = "message",
                                                      Action = new ActionLink
                                                                   {
                                                                       Href = "www.google.com",
                                                                       Text = "Coisas e tal"
                                                                   }
                                                  }
                                   },
                                 new NotificationData
                                   {
                                       Key = 2,
                                       News = new News
                                                  {
                                                      Message = "messag2e",
                                                      Action = new ActionLink
                                                                   {
                                                                       Href = "www.google.com",
                                                                       Text = "Coisas e tal22"
                                                                   }
                                                  }
                                   },

                                                                  new NotificationData
                                   {
                                       Key = 3,
                                       News = new News
                                                  {
                                                      Message = "message",
                                                      Action = new ActionLink
                                                                   {
                                                                       Href = "www.google.com",
                                                                       Text = "Coisas e tal"
                                                                   }
                                                  }
                                   },
                                 new NotificationData
                                   {
                                       Key = 4,
                                       News = new News
                                                  {
                                                      Message = "messag2e",
                                                      Action = new ActionLink
                                                                   {
                                                                       Href = "www.google.com",
                                                                       Text = "Coisas e tal22"
                                                                   }
                                                  }
                                   },

                           };
            return View("NotificationView",data);
        }
    }
}
